package board.freeboard.dao;

import java.sql.SQLException;
import java.util.List;

import util.SqlMapLocator;
import board.freeboard.dto.BoardDto;

public class BoardDao {
	private static BoardDao instance = new BoardDao();

	public static BoardDao getInstance() {
		return instance;
	}

	private BoardDao() {
	}

	@SuppressWarnings("unchecked")
	public List<BoardDto> list(int board_no) throws SQLException {
		return (List<BoardDto>) SqlMapLocator.getMapper().queryForList(
				"board.selectAll", board_no);
	}
	
	@SuppressWarnings("unchecked")
	public List<BoardDto> issueList(int board_no) throws SQLException {
		return (List<BoardDto>) SqlMapLocator.getMapper().queryForList(
				"board.hotIssue", board_no);
	}

	public BoardDto selectOne(int article_no) throws SQLException {
		return (BoardDto) SqlMapLocator.getMapper().queryForObject(
				"board.selectOne", article_no);
	}
	
	public String selectBoardName(int board_no) throws SQLException {
		return (String)SqlMapLocator.getMapper().queryForObject("board.selectBoardName", board_no);
	}
	public String selectLevelName(int member_no) throws SQLException {
		return (String)SqlMapLocator.getMapper().queryForObject("board.selectLevelName", member_no);
	}
	
	public void insert(BoardDto dto) throws SQLException {
		SqlMapLocator.getMapper().insert("board.insertBoard", dto);
	}

	public BoardDto viewAction(int article_no) throws SQLException {
		return (BoardDto) SqlMapLocator.getMapper().queryForObject(
				"board.selectOne", article_no);
	};

	public void delete(int article_no) throws SQLException {
		SqlMapLocator.getMapper().delete("board.deleteBoard", article_no);

	}

	public void updateReadHit(int article_no) throws SQLException {
		SqlMapLocator.getMapper().update("board.updateReadHit", article_no);
	}

	public void update(BoardDto dto) throws SQLException {
		SqlMapLocator.getMapper().update("board.updateBoard", dto);
	}

	public BoardDto selectPassword(BoardDto dto) throws SQLException {
		return (BoardDto) SqlMapLocator.getMapper().queryForObject(
				"board.selectPassword", dto);
	}
}
